package com.jiyi.exception;


import com.jiyi.easemob.util.UserHelp;
import com.swift.maintenance.base.AppBase;
import com.swift.maintenance.utils.ToastUtil;

import io.reactivex.Observer;

/**
 * Created by 12262 on 2016/5/30.
 */
public abstract class MyObserver<T> implements Observer<T> {

    @Override
    public void onError(Throwable e) {
//        e.printStackTrace();
        if(e instanceof ApiException){
            if (((ApiException) e).getDisplayMessage().contains("尚未登录"))
            {
                ToastUtil.getInstances().showMsg("尚未登录或该用户在其他地方登录，请重新登录！");
                // 清除环信登录
                UserHelp.getInstance().clearUser(AppBase.Context, true);
                return;
            }
            onError((ApiException)e);
        }else{
            onError(new ApiException(e,123));
        }
    }


    /**
     * 错误回调
     */
    protected abstract void onError(ApiException ex);
}
